package com.war.dao.warehousing;

import com.war.pojo.warehousing.PurchaseInfo;
import com.war.pojo.warehousing.ReturnInfo;
import com.war.pojo.warehousing.ReturnInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReturnDao {
    //查询退货单
    @Select("SELECT * FROM warehousing_return,warehousing_purchase where " +
            "warehousing_purchase.wareHousingId = warehousing_return.wareHousingId and warehousing_return.status = 1 ")
    List<ReturnInfo> selectAll(ReturnInfo returnInfo);

    //查看退货详情
    @Select("SELECT * FROM warehousing_return,warehousing_purchase where " +
            " returnId=#{returnId} and warehousing_purchase.wareHousingId = warehousing_return.wareHousingId;")
    ReturnInfo selectById(ReturnInfo returnInfo);

    //修改退货信息
    @Update("update warehousing_return set wareHousingId=#{wareHousingId},returnDate=#{returnDate}, returnNum=#{returnNum}," +
            "returnReason=#{returnReason},returnMoney=#{returnMoney} where returnId=#{returnId}")
    int editReturn(ReturnInfo returnInfo);

    //删除退货记录
    @Update("update warehousing_return set status=0 where returnId=#{returnId}")
    int delReturn(ReturnInfo returnInfo);

    //添加退货记录
    @Insert("insert into warehousing_return(wareHousingId,returnDate,returnNum,returnReason,returnMoney,status) " +
            "value(#{wareHousingId},#{returnDate},#{returnNum},#{returnReason},#{returnMoney},1)")
    int insertReturn(ReturnInfo returnInfo);

    //一系列的查询
    //根据产品名查询
    @Select("SELECT * FROM warehousing_purchase,warehousing_return where productName=#{conValue} and " +
            "warehousing_purchase.wareHousingId = warehousing_return.wareHousingId and warehousing_return.status=1")
    List<ReturnInfo> selectByProductName(ReturnInfo returnInfo);

    //根据供应商查询
    @Select("SELECT * FROM warehousing_purchase,warehousing_return where supplierName=#{conValue} and " +
            "warehousing_purchase.wareHousingId = warehousing_return.wareHousingId and warehousing_return.status=1")
    List<ReturnInfo> selectBySupplierName(ReturnInfo returnInfo);

    //根据采购员查询
    @Select("SELECT * FROM warehousing_purchase,warehousing_return where buyer=#{conValue} and " +
            "warehousing_purchase.wareHousingId = warehousing_return.wareHousingId and warehousing_return.status=1")
    List<ReturnInfo> selectByBuyer(ReturnInfo returnInfo);

    //根据退货日期范围查询查询
    @Select("select * from warehousing_purchase,warehousing_return where" +
            " warehousing_purchase.wareHousingId = warehousing_return.wareHousingId and returnDate " +
            "between #{startDate} and #{endDate} AND warehousing_return.status = 1 \n" +
            "ORDER BY STR_TO_DATE(returnDate, '%Y-%m-%d')")
    List<ReturnInfo> selectByDate(ReturnInfo returnInfo);

    //查询入库数量
    @Select("SELECT storageNum FROM warehousing_purchase where wareHousingId=#{wareHousingId}")
    int storageNumNow(PurchaseInfo purchaseInfo);

        //批量删除
    @Delete("delete FROM warehousing_return  where returnId=#{returnId}")
    int delAll(ReturnInfo returnInfo);
}
